﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Waiter.ServiceReference1;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace Waiter.UserControls
{
    public sealed partial class HoaDonViewer : UserControl
    {
        private Table table = null;
        private Bill bill = null;

        public HoaDonViewer()
        {
            this.InitializeComponent();
        }

        public HoaDonViewer(Table _table)
        {
            this.InitializeComponent();
            this.table = _table;
            init();
        }

        private async void init()
        { 
            Service1Client client = new Service1Client();
            bill = await client.GetTableCurrentBillAsync(table);
            List<BillDetails> bdList = await client.GetBillDetailsAsync(bill);
            double total = 0;
            foreach (var bd in bdList)
            {
                ChiTietHoaDonRow row = new ChiTietHoaDonRow(bd);
                this.chiTietStackPanel.Children.Add(row);
                total += bd.Price * bd.Count;
            }
            this.tongCong.Text = string.Format("Số tiền tổng cộng: {0:N0} VND", total);
        }
    }
}
